<%@ page import="com.ssmm.ssmm1.pojo.Userr" %>
<%@ page import="java.util.List" %>
<%@ page import="com.ssmm.ssmm1.service.UserService" %>
<%@ page import="org.springframework.beans.factory.annotation.Autowired" %>
<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: naojiang
  Date: 2017/7/14
  Time: 11:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>权限管理系统</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/bootstrapValidator.css">
    <link rel="stylesheet" href="css/bootstrap.css">
    <link href="css/bootstrap-responsive.css" rel="stylesheet">
    <link href="css/bootstrapValidator.min.css" rel="stylesheet" />
</head>
<body>
<div align="right" style="margin-top:0px">
    <a class="btn btn-default" data-target="#insert" data-toggle="modal" href="">添加用户</a></td>
    <div id="insert" class="modal fade" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="form-wrap">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">
                            <span>&times;</span>
                        </button>
                    </div>
                    <div class="modal-title">
                        <h1 class="text-center">添加</h1>
                    </div>
                    <div class="modal-body">
                        <form class="form-group" id="form2" name="form2" action="/user/register" method="post" novalidate>
                            <div class="modal-body">
                                <label>用户名</label>
                                <input class="form-control" type="text" name="username" autofocus="autofocus" placeholder="至少6位字母或数字">
                            </div>
                            <div class="modal-body">
                                <label>密码</label>
                                <input class="form-control" type="password" name="password" autofocus="autofocus" placeholder="至少6位字母或数字">
                            </div>
                            <div class="modal-body">
                                <label>昵称</label>
                                <input class="form-control" type="text"  name="nickname" autofocus="autofocus" placeholder="请输入昵称">
                            </div>
                            <div class="modal-body">
                                <label>性别</label>
                                <input type="radio" name="sex" value="male" >男
                                <input type="radio" name="sex" value="female">女</input>
                            </div>
                            <div class="modal-body">
                                <label>地址</label>
                                <input class="form-control" type="text" name="address" autofocus="autofocus" placeholder="请输入地址">
                            </div>
                            <div class="modal-footer">
                                <button class="btn btn-primary" type="submit" id="tijiao">提交</button>
                                <button class="btn btn-danger" data-dismiss="modal">取消</button>
                            </div>

                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<form name="form1" action="/user/list" method="post" >
    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover">


            <thead>
            <tr>
                <td>用户名查询:</td>
                <td><input type="text" name="username" value="" class="form-control"></td>

                <td><input class="btn btn-default" type="submit" name="submit" value="查询"/></td>
            </tr>

            <tr>
            <th>标识</th><th>用户名</th><th>密码</th><th>昵称</th><th>性别</th><th>地址</th>
            </tr>
            </thead>
            <tbody>
            <%
            List<Userr> list1 = new ArrayList<Userr>();
            list1 = (List<Userr>) session.getAttribute("list1");
            for(Userr u1:list1){
                System.out.println(u1);
            }
            for(Userr u:list1){
                if(u.getUsername().equals("admin")){
        %>
        <tr class="success">
            <td><%=u.getId() %></td>
            <td><%=u.getUsername() %></td>
            <td><%=u.getPassword() %></td>
            <td><%=u.getNickname() %></td>
            <td><%=u.getSex() %></td>
            <td><%=u.getAddress() %></td>
            <td><a class="btn btn-default" data-target="#update<%=u.getUsername()%>" data-toggle="modal" href="">修改</a></td>
        </tr>
        <%
        }else{
        %>
        <tr>
            <td><%=u.getId() %></td>
            <td><%=u.getUsername() %></td>
            <td><%=u.getPassword() %></td>
            <td><%=u.getNickname() %></td>
            <td><%=u.getSex() %></td>
            <td><%=u.getAddress() %></td>
            <td><a class="btn btn-default" href="/user/delete?username=<%=u.getUsername()%>">删除</a>&nbsp;<a class="btn btn-default" data-target="#update<%=u.getUsername()%>" data-toggle="modal" href="">修改</a></td>

            <div id="update<%=u.getUsername()%>" class="modal fade" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="form-wrap">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button class="close" data-dismiss="modal">
                                <span>&times;</span>
                            </button>
                        </div>
                        <div class="modal-title">
                            <h1 class="text-center">修改</h1>
                        </div>
                        <div class="modal-body">
                            <form class="form-group" id="form3" name="form3" action="/user/update" method="post" novalidate>
                                <div class="modal-body">
                                    <label>用户名</label>
                                    <%=u.getUsername()%><input type="hidden" name="username" value=<%=u.getUsername()%>>
                                </div>
                                <div class="modal-body">
                                    <label>密码</label>
                                    <input class="form-control" type="password" name="password" autofocus="autofocus" placeholder="至少6位字母或数字">
                                </div>
                                <div class="modal-body">
                                    <label>验证密码</label>
                                    <input class="form-control" type="password" name="checkPwd" autofocus="autofocus" placeholder="至少6位字母或数字">
                                </div>
                                <div class="modal-body">
                                    <label>昵称</label>
                                    <input class="form-control" type="text"  name="nickname" autofocus="autofocus" placeholder="请输入昵称">
                                </div>
                                <div class="modal-body">
                                    <label>性别</label>
                                    <input type="radio" name="sex" value="male" >男
                                    <input type="radio" name="sex" value="female">女</input>
                                </div>
                                <div class="modal-body">
                                    <label>地址</label>
                                    <input class="form-control" type="text" name="address" autofocus="autofocus" placeholder="请输入地址">
                                </div>
                                <div class="modal-footer">
                                    <button class="btn btn-primary" type="submit" id="tijiao2">提交</button>
                                    <button class="btn btn-danger" data-dismiss="modal">取消</button>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
                </div>
            </div>
        </tr>
        <%
                }
            }

        %>
            </tbody>
    </table>
    </div>

</form>

<a class="btn btn-default" href="/user/login" role="button">返回登录页面</a>
<script src="js/jquery-3.0.0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrapValidator.js"></script>
<script src="js/language/zh_CN.js"></script>
<script src="js/jquery.flot.js"></script>
<script src="js/jquery.flot.resize.js"></script>
<script src="js/jquery.js"></script>
<script src="js/bootstrapValidator.min.js"></script>
<script src="js/html5.js"></script>
<script src="js/excanvas.min.js"></script>
<script type='text/javascript'>
    var form = $('#form2');
    //$(document).ready(function () {

    form.bootstrapValidator({
        message: '输入值不合法',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            username: {
                message: '用户名不合法',
                validators: {
                    notEmpty: {
                        message: '用户名不能为空'
                    },
                    stringLength: {
                        min: 3,
                        max: 30,
                        message: '请输入3到30个字符'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9_\. \u4e00-\u9fa5 ]+$/,
                        message: '用户名只能由字母、数字、点、下划线和汉字组成 '
                    }
                }
            },
            password: {
                validators: {
                    notEmpty: {
                        message: '*新密码不能为空'
                    }
                }
            },
            checkPwd: {
             validators: {
             notEmpty: {
             message: '*确认密码不能为空'
             },
             identical: {
             field: 'password',
             message: '*两次输入密码不一致'
             }
             }
             }
            nickname: {
                validators: {
                    notEmpty: {
                        message: '*昵称不能为空'
                    }
                }
            },
            sex: {
                validators: {
                    notEmpty: {
                        message: '*性别不能为空'
                    }
                }
            },
            address: {
                validators: {
                    notEmpty: {
                        message: '*地址不能为空'
                    }
                }
            },
        }
    });
    //});
    $("#tijiao").click(function () {
//进行表单验证
        var bv = form.data('bootstrapValidator');
        bv.validate();
        $.ajax({
            type:"post",
            url:"/user/register",
            data:$("#form2").serialize(),
            success:function(data){
                $("#span-1").text(data.str);
                $('#exampleModal').modal('hide')
                $('#addModal').modal.show()
            }
        })

    });
</script>
<script type='text/javascript'>
    var form = $('#form3');
    //$(document).ready(function () {

    form.bootstrapValidator({
        message: '输入值不合法',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            password: {
                validators: {
                    notEmpty: {
                        message: '*新密码不能为空'
                    }
                }
            },
            checkPwd: {
                validators: {
                    notEmpty: {
                        message: '*确认密码不能为空'
                    },
                    identical: {
                        field: 'password',
                        message: '*两次输入密码不一致'
                    }
                }
            }
            nickname: {
                validators: {
                    notEmpty: {
                        message: '*昵称不能为空'
                    }
                }
            },
            sex: {
                validators: {
                    notEmpty: {
                        message: '*性别不能为空'
                    }
                }
            },
            address: {
                validators: {
                    notEmpty: {
                        message: '*地址不能为空'
                    }
                }
            },
        }
    });
    //});
    $("#tijiao2").click(function () {
//进行表单验证
        var bv = form.data('bootstrapValidator');
        bv.validate();
        $.ajax({
            type:"post",
            url:"/user/update",
            data:$("#form3").serialize(),
            success:function(data){
                $("#span-1").text(data.str);
                $('#exampleModal').modal('hide')
                $('#addModal').modal.show()
            }
        })

    });
</script>
</body>
</html>



